<?php
defined('BASEPATH') OR exit('No direct script access allowed');
include 'Base_admin.php';
class User extends Base_admin {
	function  __construct() {
		parent::__construct();
		$this->check_login();
	}
	public function ls($state = 0) {
//		$where = array('state' => $state);
		$where = array();
		$like = array();
		$sk_nickanme = get_parameter( 'sk_nickanme', 0, 'get' );
		$sk_mobile = get_parameter( 'sk_mobile', '', 'get' );
		$sk_uid = get_parameter( 'sk_uid', 0, 'get' );
		if($sk_uid){
			$where['id'] = $sk_uid;
		}
		if($sk_nickanme){
			$like['nickname'] = $sk_nickanme;
		}
		if($sk_mobile){
			$where['mobile'] = $sk_mobile;
		}
		$data['state'] = $state;
		$data['sk_nickanme'] = $sk_nickanme;
		$data['sk_mobile'] = $sk_mobile;
		$data['sk_uid'] = $sk_uid;
		$per_page = get_parameter('per_page', 0, 'get');
		$user_list = db_get_list( 'user_bwc', $where, page_num(), $per_page, 'subscribe_time desc,subscribe desc', '', $like );
//		dump(db_last_query());
		$data['page'] = page_make_get(
			base_url('admin/user/ls/'.$state), db_count_record_num('user_bwc', $where, $like, 'id'),  page_num(), 4
		);
		$data['user_list'] = $user_list;
		$data['login_user'] = $this->login_user;
		$this->load->view('admin/user_index', $data);
	}
	function detail($id){
		$user = user_get($id);
		$data['user'] = $user;
		$data['login_user'] = $this->login_user;
		$this->load->view('admin/user_detail', $data);
	}

	function change_status( $id, $change_status ) {
		$ret = array( 'status' => false, 'info' => 'Error' );
		$user = db_get_obj( 'user_bwc', array( 'id' => $id ) );
		if( $user ) {
			bwc_user_update( $user, array( 'status' => $change_status ) );
			$ret['status'] = TRUE;
			$ret['info'] = 'SUCCESS';
		} else {
			$ret['info'] = 'User no Exist';
		}
		echo json_encode($ret);
	}

}